package com.lagou;

import com.lagou.bean.ConsumerComponent;
import com.lagou.filter.MonitorTp;
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

import java.io.IOException;
import java.util.concurrent.*;


public class AnnotationConsumerMain {
    public static void main(String[] args) throws IOException, InterruptedException {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ConsumerConfiguration.class);
        context.start();
        ConsumerComponent service = context.getBean(ConsumerComponent.class);
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(6, 6, 1, TimeUnit.SECONDS, new ArrayBlockingQueue<>(6000));
        //开启监控
        new MonitorTp().tpMonitor();
        while (true){   
            for (int i = 0; i < 1000; i++) {
                Thread.sleep(5);
                threadPoolExecutor.execute(new Runnable() {
                    @Override
                    public void run() {
                        String   msg =  service.methodC();
                    }
                });
                threadPoolExecutor.execute(new Runnable() {
                    @Override
                    public void run() {
                        String   msg =  service.methodA();
                    }
                });
                threadPoolExecutor.execute(new Runnable() {
                    @Override
                    public void run() {
                        String   msg =  service.methodB();
                    }
                });

            }
        }

    }

    @Configuration
    @PropertySource("classpath:/dubbo-consumer.properties")
    //@EnableDubbo(scanBasePackages = "com.lagou.bean")
    @ComponentScan("com.lagou.bean")
    @EnableDubbo
    static class ConsumerConfiguration {

    }
}
